package com.applet.mallappletbackstage.controller;


import com.applet.mallappletbackstage.entity.SkillsCertificate;
import com.applet.mallappletbackstage.service.SkillsCertificateService;
import com.applet.mallappletbackstage.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author X
 * @since 2020-08-17
 */
@RestController
@RequestMapping("/mallappletbackstage/skills-certificate")
public class SkillsCertificateController {

    @Autowired
    SkillsCertificateService skillsCertificateService;

    @PostMapping
    public R getAll(@RequestBody SkillsCertificate skillsCertificate) {
        skillsCertificateService.save(skillsCertificate);
        return R.success();
    }

    /***
     * 查询该用户的技能证书
     * @param openid
     * @return
     */
    @GetMapping("/getSkills/{openid}")
    public R getSkills(@PathVariable(value = "openid")String openid) {
        List<SkillsCertificate> skillsCertificate = skillsCertificateService.getSkills(openid);
        return R.success(skillsCertificate);
    }

    /***
     * 删除职业证书
     * @param id
     * @return
     */
    @DeleteMapping("/deleteSkill/{id}")
    public R deleteSkill(@PathVariable(value = "id")String id){
        int count = skillsCertificateService.deleteSkill(id);
        if(count>0){
            return R.success("成功删除");
        }
        return R.fail("删除失败");
    }
}

